<html>
<head>
<title>nTube: About</title>
<script type="text/javascript" >
	function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
	}
	
	function canStoreData() {
		return typeof Storage == "function" || navigator.cookieEnabled;
	}

	function readSettings() {
		if (!canStoreData()) {
			return null;	
		}
		if (localStorage.getItem("_ntube_settings") != null) {
			return localStorage.getItem("_ntube_settings");
		}else {
			return getCookie("settings");
		}	
}

	function readSettingsToJSON() {
		var rs = readSettings();
		if (rs == null) {
			return null;	
		}
		return JSON.parse(b64DecodeUnicode(rs));
	}
	
	function applyTheme(themeCode) {
		console.log("[nTube: nTheming] Loading CSS for this page...");
		send_request("/api/get_css?eurl=" + themeCode, "", function () {
			console.error("[nTube: nTheming] Failed to load CSS!");
		}, function (data) {
			document.getElementById("__ntheming_global").innerHTML = data;
		});
	}
	
	function b64DecodeUnicode(str) {
    try {
 		return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {
        	return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
    	}).join(''));   	
    }catch (ex) {
    	return atob(str);	
    }
	}
	
	function send_request(url, data, onFail, onSuccess) {
	if (typeof fetch != "undefined") {
		fetch(url).then(function(response) {
    		return response.text();
   	}).then(function(json) {
   		onSuccess(json);
   	}).catch(function(ex) {
   		console.error(ex);
    		onFail();
  		});	
	}else {
		console.warn("send_request() -> Outdated browser found, attempting fallback method...");
		var http = new XMLHttpRequest();
		http.open('POST', url, true);
	   http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	   
	   var hasResponse = false;
	   //var res = "";
	   http.onreadystatechange = function() {
		if (http.readyState == 4 && http.status == 200) {
		//		res = http.responseText;
				onSuccess(http.responseText.split("\n")[4]);
			}
		}
		http.ontimeout = function() {
			alert("nTube: onTimeout() was called when fetching your video!");
		}
		http.send(data);
	}
	//var http = new XMLHttpRequest();
	//var params = data;
	//http.timeout = 0;
	//http.responseType = 'blob';
	//http.open('POST', url, true);
	//http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			
	//var hasResponse = false;
	//var res = "";
	//http.onreadystatechange = function() {
	//	if (http.readyState == 4 && http.status == 200) {
	//		res = http.responseText;
	//		onSuccess(http.responseText);
	//	}
	//}
	//http.ontimeout = function() {
	//	alert("nTube: onTimeout() was called when fetching your video!");
	//}
	//http.send(params);
	
	/*		
	var stop = false;
	var time = 0;
	while (!hasResponse) {
		if (stop) {
			break;
		}
		if (time > 1500) {
			//alert("Timeout occured, try again.");
			onFail();
			stop = true;
		}
		var ix = -1;
		time += 1;
	}*/
	}
</script>
<style type="text/css" id="__ntheming_global">
html {
	background-color: black;
	color: white;
}
</style>
<style type="text/css" id="__ntheming_global_font">
html {
	font-family: sans-serif;
	font-size: medium;
}
</style>
<style type="text/css">
a {
	text-decoration: none;
	color: inherit;
}
</style>
</head>
<body>
	<center>
		<h3>nTube</h3>
		<h4>The <span style="color: lightgreen;">n</span>ot <i style="color: red">You</i><span style="color: lightgreen;">Tube</span> Project</h4>
		<h4 lore="true" id="lore">JavaScript free-oh wait, you need it just saying, well...sort of.</h4>
		<script>
		Array.prototype.random = function () {
  			return this[Math.floor((Math.random() * this.length))];
		}
		const LORE = [
			"YouTube TOS violator!", "Destroys tracking in 3 quick and easy steps!", "Only 10 cheap payments of nothing!", "You people read this and like it? Wow.",
			"*buffers*", "nTube > HookTube, Invidious, FreeTube < YouTube's lawyers", "du du DU du DU", "Pepega &#128227; FORSAAAAAAAAAAAAAAAN", "Java IS a interperted language, just saying.",
			"Wait...this isn't Rust.", "\'Original Code\'", "Now Politcally Incorrect!", "Papa Stalin would approve over free software!", "Updates every 9 weeks! 10 weeks...11 weeks. 2 years...bad joke btw",
			"Did I make it to Reddit, Ma?", "Internet Explorer 6 is better than Brave.", "nHow nAbout nEverything nStarts nWith nThe nLetter n?", "Literally a chimp can create better lore than me."
		];
		document.getElementById("lore").innerHTML = LORE.random();
		</script>
	</center>
	<center>
		<div>
			Links
			<div style="border: 1px solid green;">
				<div style="display: inline-table;border: 1px solid green;margin: 2px;padding: 2px;">
					<img src="/resources/attr.png" alt="attr.png" width="64px" height="64px"></img>
					<p>Attributions</p>		
				</div>
				<div style="display: inline-table;border: 1px solid green;margin: 2px;padding: 2px;">
					<img src="/resources/lics.png" alt="lics.png" width="64px" height="64px"></img>
					<p>License</p>		
				</div>
				<div style="display: inline-table;border: 1px solid green;margin: 2px;padding: 2px;">
					<a href="/changelog">
						<img src="/resources/changelog.png" alt="changelog.png" width="64px" height="64px"></img>
						<p>Changelog</p>					
					</a>		
				</div>
			</div>
		</div>	
	</center>
	<div style="width: 100%;">
		<div style="border: 1px solid green; margin-bottom: 2px;">
				<p style="float: left;padding-left: 5px;">nTube Version: </p>
				<p style="float: right;padding-right: 5px;">1.5-legacy</p>
				<div style="clear: both;"></div>
		</div>
		<div style="border: 1px solid green; margin-bottom: 2px;">
				<p style="float: left;padding-left: 5px;">nullUtil Version: </p>
				<p style="float: right;padding-right: 5px;">2.6.0-beta (build 214) + 2.7 (early)</p>
				<div style="clear: both;"></div>
		</div>
		<div style="border: 1px solid green; margin-bottom: 2px;">
				<p style="float: left;padding-left: 5px;">nullUtil: Youtube API Version: </p>
				<p style="float: right;padding-right: 5px;">1.0.4.2 + 2.0_UNIMPL</p>
				<div style="clear: both;"></div>
		</div>
		<div style="border: 1px solid green; margin-bottom: 2px;">
				<p style="float: left;padding-left: 5px;">HttpServer Version: </p>
				<p style="float: right;padding-right: 5px;">2.1</p>
				<div style="clear: both;"></div>
		</div>
	</div>
	<div>
		<p style="border: 1px solid orange;padding: 3px;">
			nTube is proudly a YouTube Terms of Service violator! <br>
			Yes, that's right we break the terms of service of the site, even though it may be difficult to identify a nTube client and a true YouTube user. <br>
			Oh and also, we don't use YouTube's developer API. <br>
			Broken Term: <br style="margin-bottom: 15px;">
			<code>
				YouTube TOS, Term 4.3: <br>
				You agree not to access Content through any technology or means other than the video playback pages of the Service itself, the Embeddable Player, or other explicitly authorized means YouTube may designate. <br>
			</code>
		</p>
	</div>
</body>
<script type="text/javascript" >
var settings = readSettingsToJSON();
if (settings != null && settings.theme) {
	applyTheme(settings.theme);		
}
</script>
</html>
